#include<iostream>
#include "DoubleLinkedList.h"
using namespace std;

/// @brief 查找链表中是否存在给定值
/// @tparam DT 为模板
/// @param _list 链表
/// @param _val 给定值
/// @return 若存在，返回对应点迭代器的值，否则返回tail的迭代器值
template<typename DT>
typename DoubleLinkedList<DT>::iterator find(DoubleLinkedList<DT>& _list,DT& _val)
{
    typename DoubleLinkedList<DT>::iterator itr = _list.begin();
    while(*itr != _val && itr != _list.end())
        itr++;
    return itr;
}

/// @brief 输出链表中的所有元素
/// @tparam DT 模板
/// @param _list 链表
template<typename DT>
void print(DoubleLinkedList<DT>& _list)
{
    typename DoubleLinkedList<DT>::iterator itr = _list.begin();

    while(itr != _list.end()){
        cout << *itr << " ";
        itr++;
    }

    cout << endl;
}


int main(){
    
    DoubleLinkedList<int> L;

    for(int i = 1;i <= 5; i++){
        L.push_back(i);
    }
    print(L);

    DoubleLinkedList<int>::iterator iter;
    
    int x = 3;
    iter = find(L,x);

    L.erase(iter);

    print(L);

    iter = find(L,x);
    
    if(iter == L.end()) cout << x << " is Not Found" << endl;
    
    return 0;

}